package org.zpmis.domain.project.vo;

import lombok.Data;
import org.zpmis.domain.project.model.Project;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Data
public class GetProjectDetailVo implements Serializable {

    /**
     * 项目id
     */
    private Long id;
    /**
     * 项目名称
     */
    private String name;

    /**
     * 项目代号
     */
    private String code;

    /**
     * 项目开始时间
     */
    private String startTime;

    /**
     * 项目总工期
     */
    private BigDecimal totalTime;

    /**
     * 项目结束时间
     */
    private String endTime;

    /**
     * 合同id
     */
    private Long contractId;

    /**
     * 项目描述
     */
    private String description;

    /**
     * 项目状态 0未开始 1进行中 2已完结 3失效
     */
    private Integer status;

    /**
     * 归档状态 0未归档 1已归档
     */
    private Integer archiveStatus;

    /**
     * 附件
     */
    private String attachment;

    /**
     * 源码位置
     */
    private String sourceLocation;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建人
     */
    private String createPerson;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 合同编号
     */
    private String contractCode;

    /**
     * 合同名称
     */
    private String contractName;

    private Map<Long,String> userList;

    public static GetProjectDetailVo toGetProjectDetailVo(Project project) {
        if(project == null){
            return null;
        }
        GetProjectDetailVo projectDetailVo = new GetProjectDetailVo();
        projectDetailVo.setId(project.getId());
        projectDetailVo.setName(project.getName());
        projectDetailVo.setCode(project.getCode());
        projectDetailVo.setStartTime(project.getStartTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(project.getStartTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        projectDetailVo.setTotalTime(project.getTotalTime());
        projectDetailVo.setEndTime(project.getEndTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(project.getEndTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        projectDetailVo.setContractId(project.getContractId());
        projectDetailVo.setDescription(project.getDescription());
        projectDetailVo.setStatus(project.getStatus());
        projectDetailVo.setArchiveStatus(project.getArchiveStatus());
        projectDetailVo.setAttachment(project.getAttachment());
        projectDetailVo.setSourceLocation(project.getSourceLocation());
        projectDetailVo.setCreateId(project.getCreateId());
        projectDetailVo.setCreatePerson(project.getCreatePerson());
        projectDetailVo.setCreateTime(project.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(project.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        return projectDetailVo;
    }
}
